<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      width: 100px;
      height: 100px;
      background-color: red;
    }
  </style>
</head>

<body>
  <div class="box"></div>
  <script>
    // 1. 获取DOM对象
    const box = document.querySelector('.box')

    // 2. 给DOM对象注册事件
    // 事件三要素: 事件对象(谁) 事件名(干什么) 事件处理函数(怎么干)
    box.addEventListener('click', function () {
      this.style.width = '400px'
      this.style.backgroundColor = 'purple'
    })

    box.addEventListener('mouseenter', function () {
      console.log('鼠标进入盒子了')
      this.style.backgroundColor = 'green'
    })

    box.addEventListener('mouseleave', function () {
      console.log('鼠标离开盒子了')
      this.style.backgroundColor = 'red'
    })
  </script>
</body>

</html>